import logging

from util.date_util import *
from util.log_util import get_the_logger

desc_stock_template = 'https://fund.eastmoney.com/data/fundranking.html#tgp;c0;r;sqjzf;pn50;ddesc;qsd{};qed{};qdii;zq;gg;gzbd;gzfs;bbzt;sfbb'
desc_mixed_template = 'https://fund.eastmoney.com/data/fundranking.html#thh;c0;r;sqjzf;pn50;ddesc;qsd{};qed{};qdii;zq;gg;gzbd;gzfs;bbzt;sfbb'
desc_index_template = 'https://fund.eastmoney.com/data/fundranking.html#tzs;c0;r;sqjzf;pn50;ddesc;qsd{};qed{};qdii;zq;gg;gzbd;gzfs;bbzt;sfbb'


logger = get_the_logger(__name__)


def get_month_url(year, month):
    # 获取本月第一天
    first_day = datetime(year, month, 1)
    first_day_str = first_day.strftime('%Y%m%d')

    # 获取下个月第一天
    if month == 12:
        next_month = datetime(year + 1, 1, 1)
    else:
        next_month = datetime(year, month + 1, 1)

    # 本月最后一天
    last_day = next_month - timedelta(days=1)
    last_day_str = last_day.strftime('%Y%m%d')

    # 获取今天的日期字符串
    today = datetime.now()
    today_str = today.strftime('%Y%m%d')

    # 如果今天早于最后一天，使用今天的日期
    if today_str < last_day_str:
        last_day_str = today_str

    logger.info(desc_stock_template.format(first_day_str, last_day_str))
    logger.info(desc_mixed_template.format(first_day_str, last_day_str))
    # return first_day_str, last_day_str


def print_url(sd, ed):
    logger.info(f'stock:\n {desc_stock_template.format(sd, ed)}')
    logger.info(f'mixed:\n {desc_mixed_template.format(sd, ed)}')
    logger.info(f'index:\n {desc_index_template.format(sd, ed)}')


if __name__ == '__main__':
    # today = datetime.now()
    # today_str = today.strftime('%Y%m%d')
    #
    # first_day_of_month = today.replace(day=1)
    # first_day_str = first_day_of_month.strftime('%Y%m%d')

    # sd = before_6m_yyyymmdd()
    sd = before_1y_yyyymmdd()
    # sd = before_2y_yyyymmdd()
    # sd = before_3y_yyyymmdd()

    # ed = yesterday_yyyymmdd()
    ed = before_6m_yyyymmdd()
    # ed = before_1y_yyyymmdd()
    # ed = before_2y_yyyymmdd()
    print_url(sd, ed)

    #
    # logger.info(url1)
    # logger.info(url2)
